MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Unstring using EasyTrieve - Variable data

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Job Control Language(JCL)
View previous topic :: View next topic  
Author Message
rockstar1986
Beginner


Joined: 31 Aug 2020
Posts: 5
Topics: 1

PostPosted: Mon Aug 31, 2020 1:36 pm    Post subject: Unstring using EasyTrieve - Variable data Reply with quote

Hi,

I have the below requirement and trying to do it via JCL mostly Easytreive. I referred earlier posts by Kolusu, but since the data length is varying in my case, I couldnt fully find a solution. Please help!

Input
Code:
S{"NAME":{"NAME1":"JOHNNY C","NAME2":"BRAVO","ADDRESS1":"433 SOUTH EAST STREET","CITY":"LAS VEGAS","STATE":"NV"}}
S{"NAME":{"NAME1":"PAUL JEAN G","NAME2":"WILSON","ADDRESS1":"6000 WILLIAMS  BLVD","CITY":"TAMPA","STATE":"FL"}}
S{"NAME":{"NAME1":"MELANIE CHRIS","NAME2":"DUMMINY","ADDRESS1":"22100 VICTORY PARKWAY","CITY":"LOS ANGELES","STATE":"CA"}}


Output needs to be in formatted in fixed length as below
NAME1- 30
NAME2 - 30
ADDRESS1 - 30
CITY -17
STATE - 2

Code:

JOHNNY C                       BRAVO                   433 SOUTH EAST STREET        LAS VEGAS          NV
PAUL JEAN G                    WILSON                  6000 WILLIAMS BLVD           TAMPA              FL
MELANIE CHRIS                  DUMINIY                 22100 VICTORY PARKWAY        LOS ANGELES        CA
Back to top
View user's profile Send private message
Nic Clouston
Advanced


Joined: 01 Feb 2007
Posts: 1075
Topics: 7
Location: At Home

PostPosted: Mon Aug 31, 2020 4:13 pm    Post subject: Reply with quote

You have an Easytrieve problem not a JCL problem so why post in the JCL part of the forum instead of the Application Programming section the description of which specifically mentions Easytrieve?
_________________
Utility and Program control cards are NOT, repeat NOT, JCL.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12367
Topics: 75
Location: San Jose

PostPosted: Mon Aug 31, 2020 4:29 pm    Post subject: Re: Unstring using EasyTrieve - Variable data Reply with quote

rockstar1986 wrote:
Hi,

I have the below requirement and trying to do it via JCL mostly Easytreive. I referred earlier posts by Kolusu, but since the data length is varying in my case, I couldnt fully find a solution. Please help!


rockstar1986,

As Nic pointed, JCL doesn't anything. It is the programs/utilities that converts the variable data into fixed length data.

DFSORT can parse out the information quite easily.

Code:

//STEP0100 EXEC PGM=SORT                       
//SYSOUT   DD SYSOUT=*                         
//SORTIN   DD DISP=SHR,DSN=Your input file
//SORTOUT  DD SYSOUT=*                         
//SYSIN    DD *                                 
  OPTION COPY                                   
  INREC PARSE=(%01=(STARTAFT=C'"NAME1":"',     
                     ENDBEFR=C'",',             
                      FIXLEN=30),               
                                               
               %02=(STARTAFT=C'"NAME2":"',     
                     ENDBEFR=C'",',             
                      FIXLEN=30),               
                                               
               %03=(STARTAFT=C'"ADDRESS1":"',   
                     ENDBEFR=C'",',             
                      FIXLEN=30),               
                                               
               %04=(STARTAFT=C'"CITY":"',       
                     ENDBEFR=C'",',             
                      FIXLEN=17),               
                                               
               %05=(STARTAFT=C'"STATE":"',     
                     ENDBEFR=C'",',             
                      FIXLEN=02)),             
                                               
      BUILD=(%01,                               
             %02,                               
             %03,                               
             %04,                               
             %05)                               
/*                                             


Untested Easytrieve code

Code:

FILE INFILE                                         
     IN-REC           01 001 A OCCURS 133 INDEX IDX 
                                                     
FILE OUTPUT                                         
     O-NAME1          01 030 A                       
     O-NAME2          *  030 A                       
     O-ADDR1          *  030 A                       
     O-CITY           *  017 A                       
     O-STATE          *  002 A                       
                                                     
WS-AREA               W  030 A                       
WS-BYTE WS-AREA  1 A OCCURS 30 INDEX WDX             
WS-STR                W  001 A                       
                                                     
JOB INPUT INFILE                                     
                                                     
  WS-STR = ' '                                       
                                                     
  DO UNTIL IDX > 133                       
                                           
                                           
     IF IN-REC (IDX) 10 = '"NAME1":"'       
        WS-STR          = 'A'     
        IDX             = IDX +10         
     END-IF                                 
                                           
     IF IN-REC (IDX) 10 = '"NAME2":"'       
        WS-STR          = 'B'           
        IDX             = IDX +10   
     END-IF                                 
                                           
     IF IN-REC (IDX) 12 = '"ADDRESS1":"'   
        WS-STR          = 'C'     
        IDX             = IDX +12         
     END-IF                                 
                                           
     IF IN-REC (IDX) 09 = '"CITY":"'       
        WS-STR          = 'D'       
        IDX             = IDX +09       
     END-IF                                 
                                           
     IF IN-REC (IDX) 10 = '"STATE":"'       
        WS-STR          = 'E'         
        IDX             = IDX +10     
     END-IF                                 
                                           
     IF WS-STR = 'A'  'B' 'C' 'D' 'E'       
        PERFORM GET-DATA                   
     ELSE                                   
        IDX   = IDX + 1                     
     END-IF                                 
                                           
  END-DO                                   
  PUT OUTPUT                               
                                           
                                               
  GET-DATA. PROC                               
                                               
         WDX     = 1                           
         WS-AREA = ' '                         
         DO UNTIL IN-REC(IDX) 2 = '",'         
            WS-AREA(WDX)        = IN-REC(IDX) 
                    IDX         = IDX + 1     
                    WDX         = WDX + 1     
         END-DO                               
         CASE WS-STR                           
              WHEN 'A'                         
                  O-NAME1  = WS-AREA           
              WHEN 'B'                         
                  O-NAME2  = WS-AREA           
              WHEN 'C'                         
                  O-ADDR1  = WS-AREA           
              WHEN 'D'                         
                  O-CITY   = WS-AREA           
              WHEN 'E'                         
                  O-STATE  = WS-AREA           
          END-CASE                             
          WS-STR           = ' '                                     
  END-PROC                                     
Back to top
View user's profile Send private message Send e-mail Visit poster's website
misi01
Advanced


Joined: 02 Dec 2002
Posts: 618
Topics: 172
Location: Stockholm, Sweden

PostPosted: Wed Sep 02, 2020 4:29 am    Post subject: Reply with quote

Kolusu - I like the fact that you include 2 examples of a solution (the SORT example certainly looks easier).

Rockstar1986's actual request for an Easytrieve solution makes me think of that saying "if all you've got is a hammer, every problem looks like a nail" Smile
(I wonder if a colleague has told him that he must solve it using Easytrieve)
_________________
Michael
Back to top
View user's profile Send private message Send e-mail
rockstar1986
Beginner


Joined: 31 Aug 2020
Posts: 5
Topics: 1

PostPosted: Wed Sep 02, 2020 2:34 pm    Post subject: Re: Unstring using EasyTrieve - Variable data Reply with quote

Hi Kolusu,

Much thanks. DFSORT works for me, but got another question. I wanted to convert the lower case to upper case on one of these fields(all should be fine too) and Im using TRAN=LTOU but fails with error. Please advise.

Code:
      BUILD=(%01,                               
             %02,                               
             %03,                               
             %04,TRAN=LTOU,                             
             %05) 
Back to top
View user's profile Send private message
Nic Clouston
Advanced


Joined: 01 Feb 2007
Posts: 1075
Topics: 7
Location: At Home

PostPosted: Wed Sep 02, 2020 2:52 pm    Post subject: Reply with quote

It helps if you show the error messages.
_________________
Utility and Program control cards are NOT, repeat NOT, JCL.
Back to top
View user's profile Send private message
rockstar1986
Beginner


Joined: 31 Aug 2020
Posts: 5
Topics: 1

PostPosted: Wed Sep 02, 2020 7:24 pm    Post subject: Reply with quote

Nic, Kolusu,

I was able to fix the issue, thank you. I was wondering if we can format a header to populate all "-" in DFSORT using HEADER1 parameter instead of hardcoding .. similar to program CODE - MOVE ALL '-' TO VARIABLE

Code:

 NAME  ADDRESS                       CITY       ST
JOHN|1211 SUSAN DR                 |MORRIS CITY|CA



EXPECTED O/P
Code:

------------------------------------------------------------
 NAME  ADDRESS                       CITY       ST
------------------------------------------------------------
JOHN|1211 SUSAN DR                 |MORRIS CITY|CA
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12367
Topics: 75
Location: San Jose

PostPosted: Thu Sep 03, 2020 12:50 am    Post subject: Reply with quote

rockstar1986,

Please do NOT quote the entire post. It adds nothing but clutter.

rockstar1986 wrote:
Im using TRAN=LTOU but fails with error. Please advise.


The above is absolutely useless without you showing the relevant error messages. We cannot look over your shoulder, so post detailed information on what you're trying to accomplish. Do not make people guess what you mean. This will give you a much better chance of getting a good answer to your question.

rockstar1986 wrote:
I was wondering if we can format a header to populate all "-" in DFSORT using HEADER1 parameter instead of hardcoding .. similar to program CODE - MOVE ALL '-' TO VARIABLE


Quite simple. Add the following after the BUILD statement

Code:

  OUTFIL REMOVECC,
  HEADER1=(001:109'-',/,
           001:'NAME',
           031:'NAME2',
           061:'ADDRESS',
           091:'CITY',
           108:'ST',/,
           001:109'-')


If you're not familiar with DFSORT and DFSORT's ICETOOL, I'd suggest reading through "z/OS DFSORT: Getting Started". It's an excellent tutorial, with lots of examples, that will show you how to use DFSORT, DFSORT's ICETOOL and DFSORT Symbols. You can access it online, along with all of the other DFSORT books, from:

http://www.ibm.com/support/docview.wss?rs=114&uid=isg3T7000080
_________________
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
rockstar1986
Beginner


Joined: 31 Aug 2020
Posts: 5
Topics: 1

PostPosted: Thu Sep 03, 2020 2:20 am    Post subject: Reply with quote

Thanks Kolusu.. One more question: Please advise.
Back to the original question, in the input if any of the field is missing, then looks like DFSORT is ignoring all fields after that and goes to next line.

Example:
In the below case, 2nd line is missing NAME2 in the input, i want to simply ignore that one field but still read the next fields and display the o/p. However this is not happening and all fields are ignored in the line.

Code:

S{"NAME":{"NAME1":"JOHNNY C","NAME2":"BRAVO","ADDRESS1":"433 SOUTH EAST STREET","CITY":"LAS VEGAS","STATE":"NV"}}
S{"NAME":{"NAME1":"PAUL JEAN G","ADDRESS1":"6000 WILLIAMS  BLVD","CITY":"TAMPA","STATE":"FL"}}
S{"NAME":{"NAME1":"MELANIE CHRIS","NAME2":"DUMMINY","ADDRESS1":"22100 VICTORY PARKWAY","CITY":"LOS ANGELES","STATE":"CA"}}



DSFORT o/p

Code:


JOHNNY C                       BRAVO                   433 SOUTH EAST STREET        LAS VEGAS          NV
PAUL JEAN G                                           
MELANIE CHRIS                  DUMINIY                 22100 VICTORY PARKWAY        LOS ANGELES        CA



Expected o/p

Code:


JOHNNY C                       BRAVO                   433 SOUTH EAST STREET        LAS VEGAS          NV
PAUL JEAN G                                            6000 WILLIAMS BLVD           TAMPA              FL
MELANIE CHRIS                  DUMINIY                 22100 VICTORY PARKWAY        LOS ANGELES        CA
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12367
Topics: 75
Location: San Jose

PostPosted: Thu Sep 03, 2020 1:11 pm    Post subject: Reply with quote

rockstar1986 wrote:
Thanks Kolusu.. One more question: Please advise.
Back to the original question, in the input if any of the field is missing, then looks like DFSORT is ignoring all fields after that and goes to next line.

Example:
In the below case, 2nd line is missing NAME2 in the input, i want to simply ignore that one field but still read the next fields and display the o/p. However this is not happening and all fields are ignored in the line.


rockstar1986,

Use the following control cards

Code:

//SYSIN    DD *                                                 
  OPTION COPY                                                   
  INREC IFTHEN=(WHEN=INIT,                                     
        OVERLAY=(165:C'|',196:C'|',227:C'|',245:C'|',248:C'|')),
                                                               
        IFTHEN=(WHEN=(01,133,SS,EQ,C'"NAME1":"'),               
               PARSE=(%01=(STARTAFT=C'"NAME1":"',               
                            ENDBEFR=C'",',                     
                             FIXLEN=30)),                       
       OVERLAY=(135:%01),HIT=NEXT),                             
                                                               
        IFTHEN=(WHEN=(01,133,SS,EQ,C'"NAME2":"'),               
               PARSE=(%02=(STARTAFT=C'"NAME2":"',               
                            ENDBEFR=C'",',                     
                             FIXLEN=30)),                       
       OVERLAY=(166:%02),HIT=NEXT),                             
                                                               
        IFTHEN=(WHEN=(01,133,SS,EQ,C'"ADDRESS1":"'),           
               PARSE=(%03=(STARTAFT=C'"ADDRESS1":"',           
                            ENDBEFR=C'",',                     
                             FIXLEN=30)),                       
       OVERLAY=(197:%03),HIT=NEXT),                             
                                                               
        IFTHEN=(WHEN=(01,133,SS,EQ,C'"CITY":"'),               
               PARSE=(%04=(STARTAFT=C'"CITY":"',               
                            ENDBEFR=C'",',                     
                             FIXLEN=17)),                       
       OVERLAY=(228:%04),HIT=NEXT),                             
                                                               
        IFTHEN=(WHEN=(01,133,SS,EQ,C'"STATE":"'),               
               PARSE=(%05=(STARTAFT=C'"STATE":"',               
                            ENDBEFR=C'",',                     
                             FIXLEN=02)),                       
       OVERLAY=(246:%05))                                       
                                                               
                                                                   
  OUTFIL REMOVECC,                                                 
  BUILD=(135,114),                                                 
  HEADER1=(001:30'-','|',30'-','|',30'-','|',17'-','|',02'-','|',/,
           001:'NAME',                                             
           031:'|NAME2',                                           
           062:'|ADDRESS',                                         
           093:'|CITY',                                             
           111:'|ST|',/,                                           
           001:30'-','|',30'-','|',30'-','|',17'-','|',02'-','|')   
                                                                   
/*

_________________
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
rockstar1986
Beginner


Joined: 31 Aug 2020
Posts: 5
Topics: 1

PostPosted: Sat Sep 05, 2020 7:07 pm    Post subject: Reply with quote

Thank you Kolusu. It was a good learning on the DFSORT..
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Job Control Language(JCL) All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group