Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Can STRING into field be reference modified?

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
ballalsachin

New User


Joined: 22 Sep 2005
Posts: 15
Location: USA

PostPosted: Wed Apr 08, 2009 9:46 pm    Post subject: Reference Modification while using String
Reply with quote

Hi All,
Mine in on the similar lines. hence posting this question here

I have defined
01 WK-DETAIL-LINE PIC X(132)
01 WK-BD-EDITED PIC X(10)

In the procedure division, I am trying to concatenate as follows:

STRING 'MY FIRST STRING' DELIMITED BY SIZE
WK-BD-EDITED DELIMITED BY SIZE
INTO WK-DETAIL-LINE(38:40)

I am getting an error while compiling :

IGYPA2135-S - WK-DETAIL-LINE (ALPHANUMERIC)" WAS FOUND AS THE "STRING" RECEIVING FIELD BUT WAS REFERENCE MODIFIED. THE
STATEMENT WAS DISCARDED

What can be an issue here ?
Appreciate your help

Thanks
Back to top
View user's profile Send private message

dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Apr 08, 2009 10:07 pm    Post subject:
Reply with quote

maybe you can not use reference modification to override the RECEIVING FIELD of a STRING command?
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2150
Location: At my coffee table

PostPosted: Wed Apr 08, 2009 10:08 pm    Post subject:
Reply with quote

IBM COBOL for MVS® & VM Language Reference SC26-4769-04 wrote:
INTO Phrase

identifier-3 Represents the receiving field.

X It must not represent an edited data item or external floating-point
X item and must not be described with the JUSTIFIED clause. As an IBM
X extension, identifier-3 can be reference-modified.
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2150
Location: At my coffee table

PostPosted: Wed Apr 08, 2009 10:14 pm    Post subject:
Reply with quote

Unless otherwise specified, reference modification is allowed anywhere an identifier or function-identifier that references a data item or function with the same usage as the reference-modified data item is permitted.
I didn't see any "otherwise specified" in the STRING write-up.....
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Apr 08, 2009 10:20 pm    Post subject:
Reply with quote

maybe if 15 (length of the literal) --- delimited by size
plus 10, length of WK-BD-EDITED -- delimited by size
equaled 40, there may not have been a problem.
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2150
Location: At my coffee table

PostPosted: Wed Apr 08, 2009 10:41 pm    Post subject:
Reply with quote

dbzTHEdinosauer wrote:
maybe if 15 (length of the literal) --- delimited by size
plus 10, length of WK-BD-EDITED -- delimited by size
equaled 40, there may not have been a problem.
Are you saying that the compiler checks the length of all the sources to insure they will fill the destination?
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Apr 08, 2009 10:58 pm    Post subject:
Reply with quote

well it could, all the info is there.

if the delimiter was variable (delimited by spaces),
then the compiler would not know that you are trying to force a 40 char fill with only 25 char.
what is the STRING supposed to do when you demand a 40 char fill with only 25.

and demand is the word.
reference modification was improperly used.
in this case forcing a greater than possible length override.

If the length override was 20 instead of 40
Code:
INTO WK-DETAIL-LINE(38:20)

the OP probably would not have received an error.
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2150
Location: At my coffee table

PostPosted: Wed Apr 08, 2009 11:10 pm    Post subject:
Reply with quote

I'm going to have to disagree with you Dick.
Stringing into a data area smaller than the strung data will trigger the "on overflow" (if present).
Stringing into a data area bigger than the strung data is why we always initialize the into area.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7914
Location: Bellevue, IA

PostPosted: Wed Apr 08, 2009 11:11 pm    Post subject:
Reply with quote

From the COBOL Language Reference:
Quote:
Conceptually, when the STRING statement is executed, the initial pointer value (explicit or implicit) is the first character position within the receiving field into which data is to be transferred. Beginning at that position, data is then positioned, character-by-character, from left to right. After each character is positioned, the explicit or implicit pointer is increased by 1. The value in the pointer field is changed only in this manner. At the end of processing, the pointer value always indicates a value equal to one character position beyond the last character transferred into the receiving field.
Which implies, but does not explicitly state, that the receiving field of a STRING operation cannot be reference modified since the starting position must be the first character.
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2150
Location: At my coffee table

PostPosted: Wed Apr 08, 2009 11:22 pm    Post subject:
Reply with quote

From the COBOL Language Reference:
Quote:
Reference modification creates a unique data item that is a subset of data-name-1 or a subset of the value referenced by function-name-1 and its arguments, if any.
Which implies, but does not explicitly state, that the compiler has a valid beginning address and an implied length with which to work.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Apr 08, 2009 11:47 pm    Post subject:
Reply with quote

Quote:
starting position must be the first character

I apologize to you Robert for my briskness, but that is not true.

I have used reference mod with STRING before, because I was to lazy to define an explicit pointer (though I did with the ref mod).

but, I appreciate your quote from the doc, because the 40 (from the ref mod) says move 40 when you only have 25 to deal with.

normally, I use ref mod with a calculated length.
The OP has used a literal length that is greater than the sum of the calculable lengths of the sending fields.
The compiler was able to figure that out, since all the lengths were literals.
(delimited by size, 40).

Also, considering the compiler gave an error to the OPs code,
I tend to trust the compiler.
I have laid a lot of dumb code in my life, have not yet found a bug in the compiler. Not saying there have not been any bugs, just this kind of stuff, which if you look at the assembler code generated, is sort of obvious.

I don't have machine access at present, but if some one was to code the STRING with 40 and then again with 20, I think I will be proved correct.
Actually, do the 20 first, since we know the 40 will cause an error.

But, then again, I never used ref mod with a literal length. If I know the length, I will define my data properly so that I don't need to rookie-up the STRING with ref mod. Also, sets a precedent so that then next pgmr dealing with my program is not mislead.

(Sorry, been reading the OP-EDs and am really pissed about what is happening to my country.)
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7914
Location: Bellevue, IA

PostPosted: Wed Apr 08, 2009 11:57 pm    Post subject:
Reply with quote

OK, I was wrong ... when I tested
Code:
       01  WK-DETAIL-LINE              PIC X(132) VALUE SPACES.
       01  WK-BD-EDITED                PIC X(10) VALUE 'CCYY/MM/DD'.
      /
       PROCEDURE DIVISION.
       S1000-MAIN       SECTION.
           STRING 'MY FIRST STRING' DELIMITED BY SIZE
                  WK-BD-EDITED DELIMITED BY SIZE
             INTO WK-DETAIL-LINE (38 : 40)
             .
           DISPLAY WK-DETAIL-LINE.
produces as output
Code:
----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+---->
                                      MY FIRST STRINGCCYY/MM/DD
so your problem is either syntax or data. What version of COBOL are you running in? Try copying my STRING statement exactly as is and use it; if that still doesn't work then there's probably some problem with WK-DETAIL-LINE.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Apr 09, 2009 12:01 am    Post subject:
Reply with quote

I was, also, wrong.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7914
Location: Bellevue, IA

PostPosted: Thu Apr 09, 2009 12:05 am    Post subject:
Reply with quote

Dick: whatever's going on (and I'm starting to suspect the OP hasn't given us the full picture), the length doesn't figure into it. The pseudoassembler generated by COBOL is
Code:
000018  STRING
   000378  5820 905C               L     2,92(0,9)               TGTFIXD+92
   00037C  58F0 2098               L     15,152(0,2)             V(IGZCSTG )
   000380  4110 A0BD               LA    1,189(0,10)             PGMLIT AT +181
   000384  05EF                    BALR  14,15
so I don't see how the compiler would have flagged a length problem -- runtime, maybe, but not at compile time.
Back to top
View user's profile Send private message
Mickeydusaor

Active User


Joined: 24 May 2006
Posts: 258
Location: Salem, Oregon

PostPosted: Thu Apr 09, 2009 12:06 am    Post subject:
Reply with quote

I do this all of the time, but the total length as described in his example do not total up to 40 bytes which will generate the error. here is just a few examples using reference modifications in a string clause.




Code:
STRING 'TRANSID - '          DELIMITED BY SIZE
       CMDLINEI(01:04)       DELIMITED BY SIZE
       ' FAILED'             DELIMITED BY SIZE
  INTO WS-USER-MESSAGE
END-STRING


STRING WSSUT13W-TIME(1:2) DELIMITED BY SIZE
       WSSUT13W-TIME(4:2) DELIMITED BY SIZE
       WSSUT13W-TIME(7:2) DELIMITED BY SIZE
  INTO WS-CURRENT-TIME
END-STRING


STRING PRNTREQI(WS-FIELD-OFFSET:WS-FIELD-COUNTS)
                                DELIMITED BY SIZE
  INTO WS-WRK-FIELD
END-STRING


IF WS-FMT04-BUCKS-AMT > 0
  MOVE 0               TO F04-INDEX

  INSPECT WS-FMT04-BUCKS-AMT TALLYING F04-INDEX
                                          FOR LEADING ZEROES
ELSE
  MOVE 3               TO F04-INDEX
END-IF

IF WS-FMT07-BUCKS-AMT > 0
  MOVE 0               TO F07-INDEX

  INSPECT WS-FMT07-BUCKS-AMT TALLYING F07-INDEX
                                          FOR LEADING ZEROES
ELSE
  MOVE 3               TO F07-INDEX
END-IF
 
IF WS-FMT05-BUCKS-AMT > 0
  MOVE 0               TO F05-INDEX

  INSPECT WS-FMT05-BUCKS-AMT TALLYING F05-INDEX
                                          FOR LEADING ZEROES
ELSE
  MOVE 3               TO F05-INDEX
END-IF

IF WS-FMT06-BUCKS-AMT > 0
  MOVE 0               TO F06-INDEX

  INSPECT WS-FMT06-BUCKS-AMT TALLYING F06-INDEX
                                          FOR LEADING ZEROES
ELSE
  MOVE 3               TO F06-INDEX
END-IF

STRING 'COURT ORDER '     DELIMITED BY SIZE
       'AMT FOR '         DELIMITED BY SIZE
       'BENE CHG FROM '   DELIMITED BY SIZE
       ' - '              DELIMITED BY SIZE
       WS-FAD-SEQ         DELIMITED BY SIZE
       '$'                DELIMITED BY SIZE
       WS-FMT04-BUCKS-AMT(F04-INDEX + 1:)
                          DELIMITED BY SIZE
       '.'                DELIMITED BY SIZE
       WS-FMT04-CENTS-AMT DELIMITED BY SIZE
       ' $'               DELIMITED BY SIZE
       WS-FMT07-BUCKS-AMT(F07-INDEX + 1:)
                          DELIMITED BY SIZE
       '.'                DELIMITED BY SIZE
       WS-FMT07-CENTS-AMT DELIMITED BY SIZE
       ' TO '             DELIMITED BY SIZE
       '$'                DELIMITED BY SIZE
       WS-FMT05-BUCKS-AMT(F05-INDEX + 1:)
                          DELIMITED BY SIZE
       '.'                DELIMITED BY SIZE
               WS-FMT05-CENTS-AMT DELIMITED BY SIZE
        ' $'               DELIMITED BY SIZE
        WS-FMT06-BUCKS-AMT(F06-INDEX + 1:)
                           DELIMITED BY SIZE
        '.'                DELIMITED BY SIZE
        WS-FMT06-CENTS-AMT DELIMITED BY SIZE
   INTO TEXT-LOG-ACT-SUP-WKR-SYS
 END-STRING
Code:
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7914
Location: Bellevue, IA

PostPosted: Thu Apr 09, 2009 12:08 am    Post subject:
Reply with quote

Quote:
but the total length as described in his example do not total up to 40 bytes which will generate the error.
Check my code -- the lengths to not add up to 40, I did not get the error, and my code has been compiled and executed under Enterprise COBOL 3.4 so I know it works.
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2150
Location: At my coffee table

PostPosted: Thu Apr 09, 2009 12:11 am    Post subject: Re: Reference Modification while using String
Reply with quote

Quote:
IGYPA2135-S - WK-DETAIL-LINE (ALPHANUMERIC)" WAS FOUND AS THE "STRING" RECEIVING FIELD BUT WAS REFERENCE MODIFIED. THE
STATEMENT WAS DISCARDED
Does anything look a bit off about the error message? Like the isolated quote following the dataname?
Back to top
View user's profile Send private message
Mickeydusaor

Active User


Joined: 24 May 2006
Posts: 258
Location: Salem, Oregon

PostPosted: Thu Apr 09, 2009 12:13 am    Post subject:
Reply with quote

I did read that wrong, his output is defined a 132 which would not have created the error as stated.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Performing arithmetic on input field zh_lad DFSORT/ICETOOL 24 Tue Dec 06, 2016 8:04 pm
No new posts Add PD field from 2nd file to PD in 1st Sushant Garje DFSORT/ICETOOL 6 Thu Dec 01, 2016 4:32 pm
No new posts How to split the records using the am... vnktrrd DFSORT/ICETOOL 24 Fri Oct 28, 2016 7:33 pm
No new posts Sort records based on numeric field. Alks SYNCSORT 2 Wed Oct 19, 2016 10:14 pm
No new posts Amount field is getting corrupted whe... thesumitk SYNCSORT 5 Tue Oct 18, 2016 8:20 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us