Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Need ABAP code...

Former Member
0 Likes
623

Hi,

Here is the issue I have. Please help me with the relevant ABAP code. I am loading from a csv file.

<b>ZABC</b>:Delete the last character, if the character is "/". E.g., ABC, ABC/, AB/, etc. (Column A)

<b>ZEFG</b>: Delete the row if this field is blank. (Column C)

<b>ZHIJ</b>: Delete the first few characters till "/" including "/". E.g., acb/123, ab/a123, etc. (Column B)

I will like to use all the above in a single code in the start routine.

I look forward to your help.

Thanks

SAPBW

7 REPLIES 7
Read only

Former Member
0 Likes
602

Hi,

Once you upload the file, the data would be available in say internal table itab.

data : l_len type i,

l_temp1 type zhij,

l_temp2 type zhij.

LOOP AT ITAB.

l_len = len(itab-zabc).

if itab-zabc+l_len(1) = '/'.

l_len = l_len - 1.

itab-zabc = itab-zabc+0(l_len).

endif.

if itab-zefg is initial.

delete itab.

continue.

endif.

split itab-zhij at '/' into l_temp1 l_temp2.

itab-zhij = l_temp2.

modify itab.

ENDLOOP.

Best regards,

Prashant

Read only

Former Member
0 Likes
602

Hi,

Try this..When you get the values in an internal table ITAB...Process the internal table..

DATA: V_LEN TYPE INT4.

LOOP AT ITAB.

  • 1.

V_LEN = STRLEN( ITAB-COLUMN_A ).

V_LEN = V_LEN - 1.

ITAB-COLUMN_A = ITAB-COLUMN_A+0(V_LEN).

  • 3.

SEARCH ITAB-COLUMN_B FOR '/'.

ITAB-COLUMN_B = ITAB-COLUMN_B+SY-FDPOS.

MODIFY ITAB TRANSPORTING COLUMN_A COLUMN_B.

  • 2.

IF ITAB-COLUMN_C IS INITIAL.

DELETE ITAB.

ENDIF.

ENDLOOP.

Thanks,

Naren

Read only

0 Likes
602

hi,

try this.

so all ur data is avialble in ITAB.

data : len type i

loop at itab.

len = strlen(itab-field1).

len = len -1.

itab-field1 = itab-field1+0(len).

modify itab trasnporting field1.

2nd problm i am not sure how to do.

3rd issue.

if itab-field3 is initial.

delete itab

endif.

endloop.

rgds

anver

pls mark all hlpfula answers

Read only

former_member186741
Active Contributor
0 Likes
602

data: l_len type i.

loop at itab.

describe field itab-cola length l_len.

l_len = l_len - 1.

if itab-cola+l_len = '/'.

itab-cola+l_len = ''.

modify itab transporting cola.

endif.

if itab-colc is initial.

delete itab.

continue.

endif.

data: rubbish(1),rest like itab-colb.

split itab-colb at '/' into rubbish rest.

itab-colb = rest.

modify itab transporting colb.

endloop.

Read only

uwe_schieferstein
Active Contributor
0 Likes
602

Hello

That is my solution:

*&---------------------------------------------------------------------*
*& Report  ZUS_SDN_STRING_SPLIT
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zus_sdn_string_split.



TYPES: BEGIN OF ty_s_entry.
TYPES:   column_a  TYPE string,
         column_b  TYPE string,
         column_c  TYPE string.
TYPES: END OF ty_s_entry.

DATA:
  gd_head    TYPE string,
  gd_len     TYPE i,
  gd_offset  TYPE i,
  gs_entry   TYPE ty_s_entry,
  gt_itab    TYPE STANDARD TABLE OF ty_s_entry
             WITH DEFAULT KEY.


START-OF-SELECTION.

  gs_entry-column_a = 'ABC/'.
  gs_entry-column_b = '/abc'.
  gs_entry-column_c = 'filled'.
  APPEND gs_entry TO gt_itab.

  gs_entry-column_a = 'ABC'.
  gs_entry-column_b = '12/abc'.
  gs_entry-column_c = 'filled'.
  APPEND gs_entry TO gt_itab.

  gs_entry-column_a = 'ABC'.
  gs_entry-column_b = 'abc'.
  gs_entry-column_c = space.  " empty => should be deleted
  APPEND gs_entry TO gt_itab.

  WRITE: / 'BEFORE:'.
  PERFORM print_itab.


* (1) Remove entries where column_c is initial
  DELETE gt_itab WHERE ( column_c IS INITIAL ).
* (2) Remove preceeding and trailing characters in col a & b
  gd_offset = 1.
  LOOP AT gt_itab INTO gs_entry
                  WHERE ( column_a CA '/'  OR
                          column_b CA '/' ).

*   Assuming that the '/' can be found only as the last character.
*   Otherwise the following coding is required:
*    gd_len = STRLEN( gs_entry-column_a ) - 1.
*    IF ( gs_entry-column_a+gd_len+(1) = '/' ).

    IF ( gs_entry-column_a CA '/' ).
      SHIFT gs_entry-column_a BY gd_offset PLACES RIGHT CIRCULAR.
      IF ( gs_entry-column_a+0(1) = '/' ).
        SHIFT gs_entry-column_a LEFT DELETING LEADING '/'.
      ENDIF.
    ENDIF.

    IF ( gs_entry-column_b CA '/' ).
      SPLIT gs_entry-column_b AT '/' INTO gd_head
                                          gs_entry-column_b.
    ENDIF.
    MODIFY gt_itab FROM gs_entry.
  ENDLOOP.

  SKIP 2.
  WRITE: / 'AFTER:'.
  PERFORM print_itab.


END-OF-SELECTION.
*&---------------------------------------------------------------------*
*&      Form  print_itab
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM print_itab .

  LOOP AT gt_itab INTO gs_entry.
    WRITE: / syst-tabix,
             AT 15 '|', gs_entry-column_a,
             AT 30 '|', gs_entry-column_b,
             AT 45 '|', gs_entry-column_c.
  ENDLOOP.

ENDFORM.                    " print_itab

Regards

Uwe

Read only

0 Likes
602

I could solve the above problem by using the code in the transfer rules instead of the start routine. I used:

*To Remove"/"

REPLACE FIRST OCCURRENCE OF '/' IN TRAN_STRUCTURE-/BIC/ColumnA WITH ' '.

condense TRAN_STRUCTURE-/BIC/ColumnA.

RESULT = TRAN_STRUCTURE-/BIC/ColumnA.

________________________________________

*To remove all before "/" and "/" itself and convert rest to Upper Case

data : w_string(60).

split TRAN_STRUCTURE-/BIC/ColumnB at '/'

into TRAN_STRUCTURE-/BIC/ColumnB w_string.

TRANSLATE w_string TO UPPER CASE.

RESULT = w_string.

Thanks for your help,

SAPBW

Message was edited by: SAPBW

Read only

0 Likes
602

please award points to those who helped you.