Cobol - how to delete spaces at starting postion in di



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Cobol - how to delete spaces at starting postion in di

Postby kavalisubbarao » Tue Jul 13, 2010 3:16 pm

Hi ,

I have one question regarding elemination of spaces in cobol data item.

I have one data item,can you please tell me how to eliminate saomes spaces in starting of the string,
kavalisubbarao
 
Posts: 1
Joined: Tue Jul 13, 2010 1:59 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Cobol - how to delete spaces at starting postion in di

Postby Robert Sample » Tue Jul 13, 2010 4:00 pm

Unlike C and similar languages, COBOL variables are fixed length (except when ODO is used). So when you say you want to eliminate spaces at the start of the variable (not string -- COBOL does not have strings), what do you mean? You could mean:
1. you want the data shifted left so the first bye is not a space
2. you want to replace the spaces with some other character (such as LOW-VALUE)
but if the variable is 60 bytes, you will have 60 bytes in that variable -- spaces, LOW-VALUES, printable characters, non-printing characters, but something will be in every one of those 60 bytes.
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Cobol - how to delete spaces at starting postion in di

Postby white-shadow » Sun Jul 18, 2010 2:42 am

use inspect function.
1) inspect string replacing leading " " by " ". it will remove all spaces but still there will be one space.
so after this use move string(2:lenghth of string) to string2. it will copy ur string value in string2.
i am also a begineer so not sure. but i think it will work.
white-shadow
 
Posts: 12
Joined: Sat Jul 17, 2010 11:39 am
Has thanked: 0 time
Been thanked: 0 time

Re: Cobol - how to delete spaces at starting postion in di

Postby dick scherrer » Sun Jul 18, 2010 3:25 am

Hello,

Until kavalisubbarao clarifies the request, it is difficult to offer suggestions.

Suggest you run a few experiments with the code you suggested. You will (probably) be surprised at the "output". . .

Keep in mind that "length of string" will be the same regardless of the number of leading spaces. . . Suggest rereading the reply from Robert.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: Cobol - how to delete spaces at starting postion in di

Postby Robert Sample » Sun Jul 18, 2010 6:22 am

white shadow, ponder upon the difference between a variable (COBOL terminology) and a string (Java / C / .Net terminology). The length of a string can be 0, 1, 2, ... bytes depending upon where the terminating null (AKA LOW-VALUES in COBOL) occurs. This is not the case in COBOL. A COBOL variable defined as PIC X(60) will always contain sixty bytes -- not 59, not 1 -- 60 no more and no less. The only exception is an OCCURS DEPENDING ON (ODO) in a LINKAGE SECTION or FILE SECTION where the actual number of bytes for the variable will be whatever is in the ODO variable. A WORKING-STORAGE section ODO always reserves the maximum number of bytes, although accessing the bytes between the current ODO number and the maximum is not recommended.

Furthermore, reference modification allows for moving to the length of the variable. This is valid COBOL:
MOVE WS-VAR2 ( 2 : ) TO WS-VAR3.
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Cobol - how to delete spaces at starting postion in di

Postby white-shadow » Sun Jul 18, 2010 10:30 am

sorry, i meant that only. length of the string means size of the variable declared in the picture class.
white-shadow
 
Posts: 12
Joined: Sat Jul 17, 2010 11:39 am
Has thanked: 0 time
Been thanked: 0 time


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post