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

Splitting a Record

Former Member
0 Likes
1,148

Hi All,

I have a record that needs to be inserted into ztable before inserting i need to check if total exceeds more then 8hrs then i need to split that record into two,

first with 8hrs and rest of the hours in the second record and then insert the record.

Any suggestion abt FM or any logic would be appreciated.

Regards,

Aima.

10 REPLIES 10
Read only

Former Member
0 Likes
1,104

Aima,

The questions is not clear. No clue about the 8 hrs that you are talking about. Example records with some explanation would help.

Regards,

Ravi

Read only

0 Likes
1,104

Hi RaviKumar,

let me go in this way...

For Example i have a record like

eno ename worktime .

100 xyz 12

The total time here is 12 now i need to split up the record in to two.

eno ename shft worktime

100 xyz 01 8

100 xyz 02 4

Based on start time i decide which shift the record sits.

Hope i am clear .

Regards,

Aima

Read only

Former Member
0 Likes
1,104

I am assuming that the records are stored in an internal table , not coming from file.

REPORT ztest_table.

data: begin of itab occurs 0,

hours type p,

data1(50),

data2(60),

end of itab.

data: wa like line of itab.

data: rest_hours type p.

*----populate itab..

loop at itab into wa.

if wa-hours > '8.00'.

rest_hours = wa-hours - 8.

endif.

insert into ztable values wa. "first record.

wa-hour = rest_hour.

insert into ztable values wa. "second record.

endloop.

Read only

Former Member
0 Likes
1,104

Hi,

You can manually calculate the total and if the total exceeds 8hrs, you can use COPI_STRING_SPLIT function module to split the string and populate an internal table, use the internal table to insert into dbtable.

Hope this helps,

Rgds,

Read only

0 Likes
1,104

Hi,

use function <b>ceil</b>-

here's a sample:

DATA hmenge TYPE ekpo-menge.
DATA x TYPE p DECIMALS 0.

LOOP AT itab.
  x = ceil( itab-menge / 8 ).
*gt 8
  IF x > 1.
    hmenge = itab-menge.

    WHILE hmenge > 0.
      ztab = itab.

      IF hmenge > 8.
        ztab-menge = 8.
        APPEND ztab.
      ELSE.
*end
        ztab-menge = hmenge.
        APPEND ztab.
        EXIT.
      ENDIF.

      SUBTRACT 8 FROM hmenge.

    ENDWHILE.
  ELSE.
    APPEND itab TO ztab.
  ENDIF.

ENDLOOP.

regards Andreas

Read only

0 Likes
1,104

Hi,

Since this was the continuation of the same problem, i attached my querie in the same thread,

Do we have the concept of Recurrsive call in ABAP,

I mean i would like to call same loop if condition is not satisfied.

ex loop at itab.

.....

if x ne y

<b>Can i again call the same loop</b>.

endloop

Regards,

Aima.

Read only

0 Likes
1,104

Are you saying that you want to do something like this..



loop at itab.
.....
if x ne y

   loop at itab.
   .....
   if x ne y
   endif.
   endloop

endif.

endloop



You can, but what is the point.

Regards,

Rich Heilman

Read only

0 Likes
1,104

Hi Rich,

yes u r true i would like to go for that coz every time when i loop my values for the loop get changed, hence would like to go for tat.

Any other suggestion then plz...

Regards,

Aima

Read only

0 Likes
1,104

loop at itab.

if x ne y.

continue.

endif.

endloop.

Read only

0 Likes
1,104

Hi

I don't know if you have integer numbers, if it's so:

LOOP AT ITAB WHERE SHFT = '00'.

CHECK ITAB-WORKTIME > 8.

TIMES = ITAB-WORKTIME DIV 8.

REST = ITAB-WORTIME MOD 8.

DO TIMES TIMES.

ITAB-WORKTIME = 8.

MOVE SY-INDEX TO ITAB-SHFT.

APPEND ITAB.

ENDDO.

ITAB-SHFT = ITAB-SHFT + 1.

ITAB-WORKTIME = REST.

MODIFY ITAB.

ENDLOOP.

Max

Message was edited by: max bianchi