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

hw to write code for combinations???????

former_member645692
Participant
0 Likes
403

hi all,

i have a small development to be done.

There is a company manufacturing products in different locations.for example it produces a product of quantiy 4 in 3 different locations.The total combinations for this is 15.it will be like this.

location1 location2 location3

(L1) (L2) (L3)

0 0 4

0 1 3

0 2 2

. . .

. . .

. . .

My requirerment is if i give the quantity and location,i want the combinations to be displayed in output.

If anyone knows the logic,help me.

2 REPLIES 2
Read only

Former Member
0 Likes
377

Hi,

You can loop at your first internal table and read the 2nd one ... so like this for one particular location you can get all the quantities...

Read only

former_member435013
Active Participant
0 Likes
377

Hi,

try this:

REPORT  zhabitest2.

TYPES:
  quan_t(3) TYPE n.

PARAMETERS:
  quan TYPE quan_t DEFAULT 6,
  loc(2) TYPE n DEFAULT 5.

DATA:
  qltab TYPE quan_t OCCURS 0 WITH HEADER LINE.

DO loc TIMES.
  APPEND qltab.
ENDDO.

PERFORM give_all TABLES qltab
                 USING  1
                        quan.
.
WRITE: / 'End!'.




*&---------------------------------------------------------------------*
*&      Form  GIVE_ALL
*&---------------------------------------------------------------------*
FORM give_all  TABLES   qltab
               USING    start
                        remain_quan.

  IF start > loc.
    IF remain_quan = 0.
      NEW-LINE.
      LOOP AT qltab.
        WRITE: qltab.
      ENDLOOP.
    ENDIF.
    EXIT.
  ENDIF.

  IF remain_quan = 0.
    NEW-LINE.
    LOOP AT qltab.
      WRITE: qltab.
    ENDLOOP.
    EXIT.
  ENDIF.

  DATA:
    quan TYPE quan_t,
    new_remain_quan TYPE quan_t,
    new_start(2) TYPE n,
    new_qltab TYPE quan_t OCCURS 0 WITH HEADER LINE.

  new_start = start + 1.
  DO.
    READ TABLE qltab INDEX start.
    qltab = quan.
    MODIFY qltab INDEX start.
    new_remain_quan = remain_quan - quan.
    new_qltab[] = qltab[].
    PERFORM give_all TABLES new_qltab
                     USING  new_start
                            new_remain_quan.
    IF quan = remain_quan.
      EXIT.
    ELSE.
      quan = quan + 1.
    ENDIF.
  ENDDO.

ENDFORM.                    " GIVE_ALL

Regards

Walter Habich

Moderator message - Please format your code.

Edited by: Rob Burbank on Jun 11, 2009 10:58 AM